package com.wr.hangzhounewlight.service.frontend;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wr.hangzhounewlight.mapper.SiloRawMaterialMapMapper;
import com.wr.hangzhounewlight.obj.database.SiloRawMaterialMapEntity;
import com.wr.hangzhounewlight.obj.dto.frontend.R;
import com.wr.hangzhounewlight.obj.dto.frontend.SiloManagementDTO;
import com.wr.hangzhounewlight.obj.vo.frontend.SiloManagementVO;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author yuanzhizhuo
 * createDate 2025/11/14
 */
@Service
public class SiloManagementService {

    private SiloRawMaterialMapMapper siloRawMaterialMapMapper;

    public SiloManagementService(SiloRawMaterialMapMapper siloRawMaterialMapMapper) {
        this.siloRawMaterialMapMapper = siloRawMaterialMapMapper;
    }

    public R querySilo(SiloManagementDTO dto) {
        LambdaQueryWrapper<SiloRawMaterialMapEntity> queryWrapper = new LambdaQueryWrapper<SiloRawMaterialMapEntity>()
                .select(
                        SiloRawMaterialMapEntity::getWorkshop, SiloRawMaterialMapEntity::getSilo,
                        SiloRawMaterialMapEntity::getMaterialId, SiloRawMaterialMapEntity::getMaterialCode,
                        SiloRawMaterialMapEntity::getMaterialName
                )
                .eq(SiloRawMaterialMapEntity::getWorkshop, dto.getWorkshop());
        List<SiloManagementVO> voList = siloRawMaterialMapMapper.selectList(queryWrapper).stream().map(SiloManagementVO::new).toList();
        return new R(200, "success", voList);
    }

}
